package com.yr.feiyu.common.base;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
/**
 * 
 * <p class="detail">
 * 描述：统计在线人数监听
 * </p>
 * @ClassName: OnlineCountListener
 * @version V1.0  
 * @date 2015年11月9日 
 * @author <a href="mailto:1435290472@qq.com">zq</a>
 */
public class OnlineCountListener implements HttpSessionListener{
	private static int sessionCount = 0; 
	
	@Override
	public void sessionCreated(HttpSessionEvent event) {
		HttpSession session = event.getSession(); 
		ServletContext application = session.getServletContext(); 
		sessionCount++; 
		application.setAttribute("onlineCount", sessionCount);
	}

	@Override
	public void sessionDestroyed(HttpSessionEvent event) {
		HttpSession session = event.getSession(); 
		ServletContext application = session.getServletContext(); 
		if(sessionCount >= 1){ 
			sessionCount = sessionCount-1; 
		} 
		application.setAttribute("onlineCount", sessionCount); 
	}

}
